package com.imy.virtual.server.lua;

import android.content.Context;
import android.util.Log;

import com.imy.luasupport.core.LuaCore;
import com.imy.luasupport.interfaces.ICallVirtualListener;
import com.imy.virtual.client.core.VirtualCore;
import com.imy.virtual.server.interfaces.ILuaManager;

import java.util.concurrent.atomic.AtomicReference;

public class LuaMangerService implements ILuaManager, ICallVirtualListener {
    private static final AtomicReference<LuaMangerService> gService = new AtomicReference<>();

    private Context mContext;
    private LuaMangerService(Context context) {
        mContext = context;
        LuaCore.get().setCallVirtualListener(this);
    }
    public static void systemReady(Context context) {
        LuaCore.get().init(context);
        LuaMangerService instance = new LuaMangerService(context);
        gService.set(instance);

        //注册
    }

    public static LuaMangerService get() {
        return gService.get();
    }


    @Override
    public void onMain() throws IllegalArgumentException {
        LuaCore.get().getIAppLoad().onMain();
    }

    @Override
    public int launchApp(String packageName) {
        Log.i("ALog","执行了启动app 进程:"+VirtualCore.get().getProcessName());
        return VirtualCore.get().launchApp(packageName);
    }
}
